package com.example.demo.common.utils.demo;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.common.utils.BaseResponse;
import com.example.demo.common.utils.HttpUtil;
import com.example.demo.common.utils.RSAHelper;
import com.example.demo.common.utils.demo.common.Config;
import com.example.demo.common.utils.demo.model.AvailableCreditRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by zhangws on 2019/9/18 15:01.
 * 个人可用余额查询
 */
public class PersonAvailable {
    static Logger log = LoggerFactory.getLogger(PersonAvailable.class);

    public static void queryAvailable(AvailableCreditRequest availableCreditRequest) {
        String url = Config.baseUrl + "/open/api/v1/available/credit";
        String paramsJson = JSONObject.toJSONString(availableCreditRequest);
        BaseResponse baseResponse = HttpUtil.post(url, paramsJson, Config.appKey, Config.secretkey, Config.publicKey);
        //公钥解密
        if (baseResponse.getData() != null) {
            String rs = baseResponse.getData().toString();
            try {
                String dec = RSAHelper.decryptByPublicKey(rs, Config.publicKey);
                log.info("解密结果:{}", dec);
            } catch (Exception e) {
                log.error("publicKey 有误");
            }
        }
    }
}
